package com.prestamomo.vil.ppa.pmvilpage.pmfitter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.prestamomo.vil.ppa.R;
import com.prestamomo.vil.ppa.pmvilapi.PmvilBanks;
import com.prestamomo.vil.ppa.pmvilapi.PmvilSerConfig;

import java.util.List;

public class PmvilBankFiter extends RecyclerView.Adapter<PmvilBankFiter.PmvilBankHolde> {
    private Context pmvilBankCont;
    private List<PmvilBanks.BankListPmvil> pmvilBankList;

    public PmvilBankFiter(Context pmvilBankCont, List<PmvilBanks.BankListPmvil> pmvilBankList) {
        this.pmvilBankCont = pmvilBankCont;
        this.pmvilBankList = pmvilBankList;
    }

    @NonNull
    @Override
    public PmvilBankFiter.PmvilBankHolde onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PmvilBankHolde(LayoutInflater.from(pmvilBankCont).inflate(R.layout.source_pmvil_pop_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull PmvilBankFiter.PmvilBankHolde holder, int position) {
        holder.bankPmvilPopitemTv.setText(pmvilBankList.get(position).getPmvilbankName());
        holder.bankPmvilPopitemTv.setOnClickListener(v -> {
            if(bankFilerIngter!=null){
                bankFilerIngter.setPmvilBankCheckBean(pmvilBankList.get(position));
            }
        });

    }

    @Override
    public int getItemCount() {
        return pmvilBankList==null?0:pmvilBankList.size();
    }

    public class PmvilBankHolde extends RecyclerView.ViewHolder{
        private TextView bankPmvilPopitemTv;
        public PmvilBankHolde(@NonNull View itemView) {
            super(itemView);
            bankPmvilPopitemTv = itemView.findViewById(R.id.source_pmvil_pop_item_tv);
        }
    }

    public interface BamlFilerIngter{
        void setPmvilBankCheckBean(PmvilBanks.BankListPmvil pmvilBankPopBen);
    }

    private BamlFilerIngter bankFilerIngter;

    public void setBankFilerIngter(BamlFilerIngter bankFilerIngter) {
        this.bankFilerIngter = bankFilerIngter;
    }
}
